import request from '../utils/request';


export async function fetch(shopId, branchNo, salemanId, type) {
  return await request('/tasks', { params: { shopId, branchNo, salemanId, type } });
}

export async function complete(shopId, salemanId, cardNo, completeType, reason, way, taskType, subTaskType) {
  return await request(`/shop/${shopId}/saleman/${salemanId}/task/${encodeURIComponent(cardNo)}`, {
    method: 'put',
    body: { completeType, reason, way, taskType, subTaskType },
  });
}

export async function fetchMyTask(shopId, branchNo, salemanId, complete, success, isExpired, nextPage, key, startDate, endDate) {
  const baseUrlString = `/shop/${shopId}/`;
  // let urlString;
  // if (branchNo) {
  //   urlString = `${baseUrlString}branch/${branchNo}/`;
  // }
  // if (salemanId) {
  //   urlString = `${baseUrlString}saleman/${salemanId}/`;
  // }

  return await request('/myTasks', {
    params: { shopId, branchNo, salemanId, complete, success, isExpired, page: nextPage, key, startDate, endDate },
  });
}

export async function fetchItemCls(shopId) {
  let filter = JSON.stringify({ shopId, $or: [{ cls_parent: null }, { cls_parent: '' }, { cls_parent: 'null' }] });
  if (shopId === 'sixun_000014') {
    filter = JSON.stringify({ shopId });
  }
  return await request('/itemCls', {
    params: { filter },
  });
}

export async function fetchBrandsTop10(shopId, startDate, endDate) {
  return await request('/brandsTop10', {
    // params: { filter: JSON.stringify({ shopId, oper_date: { $gte: startDate, $lte: endDate } }) },
    params: { filter: JSON.stringify({ shopId }) },
  });
}

export async function customizeTaskList(shopId) {
  return await request(`/shop/${shopId}/customizeTask`, {
    params: { filter: JSON.stringify({ status: true }) },
  });
}

export async function myVisitTasks(shopId, branch_no, card_no, complete) {
  return await request(`/myVisitTasks`, {
    params: {
      shopId,
      branch_no,
      card_no,
      // complete,
    }
  })
}

export async function cancelTask(shopId, branch_no, card_no, saleMan) {
  return await request(`/myVisitTasks`, {
    method: "post",
    body: {
      shopId,
      branch_no,
      card_no,
      saleMan,
    }
  })
}
